import {
    NAVARR_LIST_REQUEST,
    NAVARR_LIST_SUCCESS,
    NAVARR_INDEX_SUCCESS,
    GET_SEARCH_KEYWORD_SUCCESS
} from '../actions/types'
import { createReducer } from 'redux-immutablejs'
import {fromJS} from 'immutable'

const initialState = fromJS({
  items: [ {"url":"/","name":"首页",id:0}],
  navIndex:0,
  searchList:[],
})

export const navArrList = createReducer(initialState,{
  [NAVARR_LIST_SUCCESS]: (state,action)=>{
    var navArr=[];
    action.req.data.info.forEach(function(e,index){
                                             navArr.push({"url":"/list/"+e.id,"name":e.name,"id":e.id});//
                                      });
    return state.merge({
      items:[{"url":"/","name":"首页",id:0}].concat(navArr)
    })
  },
  [NAVARR_INDEX_SUCCESS]:(state,action)=>{
    return state.merge({
      navIndex:action.index
    })
  },
  [GET_SEARCH_KEYWORD_SUCCESS]:(state,action)=>{
      return state.merge({
        searchList:action.req.data.info
      })
  }
})




//export const articleDetail = createReducer(fromJS({}),{
//  [ARTICLE_DETAIL_SUCCESS]:(state,action)=>state.merge(action.articleDetail),
//  [ARTICLE_DETAIL_FAILURE]:(state,action)=>state,
//  [TOGGLE_LIKE_SUCCESS]:(state,action)=>{
//    return state.merge({
//      isLike:action.isLike,
//      like_count:action.like_count
//    })
//  },
//  [TOGGLE_LIKE_FAILURE]:(state,action)=>state
//})
//
//export const prenextArticle = createReducer(fromJS({
//  'next':{},'prev':{}
//}),{
//  [PRENEXT_ARTICLE_SUCCESS]:(state,{json})=>{
//    return state.merge(json.data)
//  },
//  [PRENEXT_ARTICLE_FAILURE]:(state,{json})=>state
//})